//
//  ValidateUtil.swift
//  ComponentUtils
//
//  Created by wrs on 2018/7/23.
//  Copyright © 2018年 wrs. All rights reserved.
//

import Foundation

public func isChinese(_ str: String) -> Bool{
    let regex = "(^[\\u4e00-\\u9fa5]+$)"
   let pred = NSPredicate(format: "SELF MATCHES %@", regex)
    if pred.evaluate(with: str) {
        return true
    } else {
        return false
    }
}

public func isValidEmail(_ str: String) -> Bool{
    if str.count == 0 {
        return false
    }
    if str.contains("@") {
        let arrays:[String] = str.components(separatedBy: "@")
        if arrays.count > 1 {
            let secondStr: String = arrays[1]
            if secondStr.contains(".") {
                return true
            }
        }
    }
    
    return false
//    let regex = "SELF MATCHES (^[\\u4e00-\\u9fa5]+$)"
//    return validRegex(str: str, regex: regex)
}

public func validRegex(str: String, regex: String) -> Bool{
    let pred = NSPredicate(format: "%@", regex)
    if pred.evaluate(with: str) {
        return true
    } else {
        return false
    }
}
